﻿package KK.GameBase {
	import KK.EMVC.Control.Control;
	import KK.System.IApplicationManager;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.system.ApplicationDomain;
	import flash.utils.Dictionary;
	
	public class BaseUI extends Control implements IEventBase ,IBaseUI{
		
		protected var mc:DisplayObjectContainer;
		 
		
//		protected var _resManager:IApplicationManager;
//		private var app:ApplicationDomain;
		
		public function BaseUI():void {
			// constructor code
			super();
			init();
		}
		 
		
		
		private function init():void
		{
		}
		
		/**
		 * 设置显示对象 
		 * @param mc
		 * @return 
		 * 
		 */
		public function SetMC(mc:DisplayObjectContainer):void
		{
			this.mc=mc;
			//this.mc.stop();
			mc.addEventListener(Event.ADDED_TO_STAGE,added); 
		} 
		/**
		 * 已经添加到场景 
		 * @param event
		 * 
		 */
		private  function added(event:Event):void
		{ 
			initMC(); 
			mc.removeEventListener(Event.ADDED_TO_STAGE,added);
		}
		protected function initMC():void
		{ 
		}
		/**
		 * 设置对象为button 
		 * @param mc
		 * @param mode
		 * @return 
		 * 
		 */
		protected function SetButton(mc:MovieClip,mode:Boolean=true):void
		{
			mc.stop();
			mc.buttonMode=mode;
			mc.addEventListener(MouseEvent.MOUSE_DOWN,MouseDown);
			mc.addEventListener(MouseEvent.MOUSE_OUT,MouseOut);
			mc.addEventListener(MouseEvent.MOUSE_OVER,MouseOver);
			
			mc.addEventListener(MouseEvent.MOUSE_UP,MouseUp);
			
			
		}


		/**
		 * 鼠标弹起事件 
		 * @param event
		 * @return 
		 * 
		 */
		private function MouseUp(event:MouseEvent):void
		{ 
			event.currentTarget.gotoAndStop(1);
		}
		/**
		 * 鼠标over
		 * @param event
		 * @return 
		 * 
		 */
		static private function MouseOver(event:MouseEvent):void
		{ 
			event.currentTarget.gotoAndStop(2);
		}
		/**
		 * 鼠标 out
		 * @param event
		 * @return 
		 * 
		 */
		static private  function MouseOut(event:MouseEvent):void
		{ 
			event.currentTarget.gotoAndStop(1);
			
		}
		static private function MouseDown(event:MouseEvent):void
		{ 
			event.currentTarget.gotoAndStop(3);
			
		}
		/**
		 * 获取MC； 
		 * @return 
		 * 
		 */
		public function GetMC():DisplayObjectContainer
		{
			return mc;
		}

		
		/**
		 * 从场景移除 
		 * @param child
		 * 
		 */
		public function removeChild(child:DisplayObject):void{
			mc.removeChild(child);
		}
		/**
		 * 添加到场景 
		 * @param child
		 * 
		 */
		public function addChild(child:DisplayObject):void{
			mc.addChild(child);
		}
		
		/**
		 * 添加对象场景 (IBaseUI)
		 * @param child
		 * 
		 */
		public function addView(child:IBaseUI):void{
			addChild(child.GetMC());
		}
		
	}
	
}
